/*
 ============================================================================
 文件名 	: EasyBounceRankContainer.cpp
 描述		: EasyBounceRankContainer类的实现.
 ============================================================================
 */

//引用
#include <eikbtgpc.h>
#include <aknmessagequerydialog.h>
#include "coedef.h"

#include <EasyBounce.rsg>
#include "EasyBounceRankView.h"
#include "EasyBounceRankContainer.h"
#include "EasyBounceRankList.h"


// ================= 函数实现 =======================

// ---------------------------------------------------------
// ConstructL()
// 两阶段构造函数
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    
    //构造Listbox
    iListBox = new (ELeave) CAknDoubleNumberStyleListBox;
    iListBox->SetContainerWindowL(*this);
    iListBox->ConstructL(this, EAknListBoxSelectionList);
    iListBox->CreateScrollBarFrameL(ETrue);
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
    iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
    iListBox->ActivateL();
    
    iList = CEasyBounceRankList::NewL();
    
    InitListBox();
    
    //RankListTest();
    
    SetRect(aRect);
    ActivateL();
    }

// -----------------------------------------------------------------------------
// CEasyBounceRankContainer::CEasyBounceRankContainer()
// C++默认构造函数.
// -----------------------------------------------------------------------------
//
CEasyBounceRankContainer::CEasyBounceRankContainer(CEasyBounceRankView* aView) : iView(aView)
	{
	
	}

// ---------------------------------------------------------------------------
// CEasyBounceRankContainer::~CEasyBounceRankContainer()
// 析构函数.
// ---------------------------------------------------------------------------
//
CEasyBounceRankContainer::~CEasyBounceRankContainer()
    {
    delete iListBox;
    iListBox = NULL;
    
    delete iList;
    iList = NULL;
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::DeleteItemFromRank()
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::DeleteItemFromRank()
	{
	//空实现
	}

// ---------------------------------------------------------
// CEasyBounceRankContainer::SizeChanged()
// 此函数在控件大小发生变化时被框架调用.
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::SizeChanged()
    {
    iListBox->SetExtent( TPoint( 0, 0 ), Rect().Size() );
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::InitListBox()
// 初始化Listbox
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::InitListBox()
	{
	CDesCArray* items = 
	    static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() );
	    
	iList->GetRankDataL( items );
	    
    iListBox->HandleItemAdditionL();
    //iListBox->SetCurrentItemIndex(0);
   
    iListBox->DrawNow();
	}

// ---------------------------------------------------------
// CEasyBounceRankContainer::CountComponentControls()
// 此函数被框架调用，返回容器中的控件个数.
// ---------------------------------------------------------
//
TInt CEasyBounceRankContainer::CountComponentControls() const
    {
    return 1; 
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::ComponentControl()
// 此函数被框架调用，返回指定的控件.
// ---------------------------------------------------------
//
CCoeControl* CEasyBounceRankContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
        	return iListBox;
        	break;
        default:
            return NULL;
        }
    }


// ---------------------------------------------------------
// CEasyBounceRankContainer::OffeKeyEventL()
// 处理按键事件
// ---------------------------------------------------------
//
TKeyResponse CEasyBounceRankContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType)
    {
    TKeyResponse ret;

    TInt code = aKeyEvent.iCode;
    switch(code)
        {
        case EKeyLeftArrow:
        case EKeyRightArrow:
        	ret = EKeyWasNotConsumed;
        	break;
        default:
            //除上面列出的按键外，其他按键事件交给Listbox处理
            ret = iListBox->OfferKeyEventL( aKeyEvent, aType );
            break;
        }
    return ret;
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::Draw()
// 每次刷新屏幕的时候，重新绘制直线以及背景等
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbWhite);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::HandleControlEventL()
// 处理控件事件    
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    //空实现
    }

// ---------------------------------------------------------
// CEasyBounceRankContainer::RankListTest()
// 测试函数 
// ---------------------------------------------------------
//
void CEasyBounceRankContainer::RankListTest()
	{
	if ( iList->SetNewRecord( 100 ) )
		{
		TBuf<20> text;
		TBuf<20> prompt(_L("Enter your name"));
	
		CAknTextQueryDialog *dlg = new (ELeave) CAknTextQueryDialog( text, prompt );
	
		dlg->SetMaxLength(20);
		if ( dlg->ExecuteLD( R_TEXT_QUERY_DIALOG ) )
			{
			iList->SetName( text );
			}
		InitListBox();
		}
	}

// ---------------------------------------------------------
// CEasyBounceRankContainer::RankListTest()
// 返回Listbox的指针
// ---------------------------------------------------------
//
CAknDoubleNumberStyleListBox* CEasyBounceRankContainer::ListBox()
	{
	return iListBox;
	}

// ---------------------------------------------------------
// CEasyBounceRankContainer::RankListTest()
// 返回Ranklist的指针
// ---------------------------------------------------------
//
CEasyBounceRankList* CEasyBounceRankContainer::RankList()
	{
	return iList;
	}

// 文件结束

